#ifndef HELPERS_H
#define HELPERS_H

#include <string>
#include <iostream>

#include <GL/glew.h>
#include <GL/gl.h>

using std::string;

namespace
{
    inline string intToString(int i)
    {    
        char numstr[21]; // Enough to hold all numbers up to 64-bits.
        sprintf(numstr, "%i", i);
        string result(numstr);
        return result;
    }

    inline string uintToString(unsigned int i)
    {
        char numstr[21]; // Enough to hold all numbers up to 64-bits.
        sprintf(numstr, "%u", i);
        string result(numstr);
        return result;
    }

    void checkGlErrors()
    {
        GLenum err = glGetError();
        string error = "No error";

        if (err != GL_NO_ERROR)
        {
            switch (err)
            {
                case GL_INVALID_ENUM : 
                    error = "Invalid enum"; 
                    break;
                case GL_INVALID_VALUE : 
                    error = "Invalid value"; break;
                case GL_INVALID_OPERATION : 
                    error = "Invalid operation"; 
                    break;
                case GL_INVALID_FRAMEBUFFER_OPERATION : 
                    error = "Invalid framebuffer operation"; 
                    break;
                case GL_OUT_OF_MEMORY : 
                    error = "Out of memory"; 
                    break;
                case GL_STACK_UNDERFLOW : 
                    error = "Stack underflow"; 
                    break;
                case GL_STACK_OVERFLOW : 
                    error = "Stack overflow"; 
                    break;
            }
        }

        std::cout << error << std::endl;
    }
}

#endif // HELPERS_H